Micro.blogとScrapboxに同時にポストするDrafts Scripts
code:javascript
/*
post to Micro.blog hosted account using Micropub API and scrapbox.
*/
// First run, you will be prompted for
// App Token. Generate tokens on the Micro.blog
// Account page
var credential = Credential.create("Micro.blog", "Insert Micro.blog app token generated on Micro.blog account page.");
credential.addTextField("apptoken", "App Token");
credential.authorize();
var appToken = credential.getValue("apptoken");
// Setup micro.blog API and content
var content = draft.content
// create and post HTTP request
var http = HTTP.create();
var response = http.request({
"url": endpoint,
"method": "POST",
"encoding": "form",
"data": {
"h": "entry",
"content": content
},
"headers": {
"Authorization": "Bearer " + appToken
}
});
var res = JSON.parse(response.responseText);
console.log("Response: " + response.statusCode);
console.log("URL: " + res.url);
if (response.statusCode != 200 && response.statusCode != 202) {
context.fail();
}
//Post to Scrapbox
//https:をsbporter:にすればPorter for Scrapboxでひらきます
// Setup for Scrapbox
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth()+1;
const date = now.getDate();
const ymd = year + '/' + month + '/' + date
var cited = content.split("\n").map(x => '> ' + x).join("\n");
var url = homeUrl + encodeURIComponent(ymd) + "?body=" + encodeURIComponent(cited + "\n" + res.url + "\n");
console.log("Scrapbox URL:" + url);
app.openURL(url);
editor.focus();